import request from '@/utils/request'
import type { registerParams, registerResponse,loginParams,loginResponse,updateUserParams } from '@/types/user'

// 注册接口
export const registerAPI = (data: registerParams) => {
  return request.post<registerResponse>('/user/insert', data)
}
// 登录接口
export const loginAPI = (data: loginParams) => {
  return request.post<loginResponse>('/user/login', data)
}

// 获取所有用户
export const getAllUsersAPI = () => {
  return request.get('/user/getAll')
}


// 更新·用户
export const updateUserAPI = (data: updateUserParams) => {
  return request.put('/user/update', data)
}


// 删除用户
export const deleteUserAPI = (id: number) => {
  return request.delete(`/user/delete/${id}`)
}

// 获取当前用户信息
export const getCurrentUserAPI = (id: number) => {
  return request.get(`/user/get/${id}`)
}

// 修改密码
export const updatePasswordAPI = (data: { userId: number, oldPassword: string, newPassword: string }) => {
  return request.put('/user/editPassword', data)
}

// 上传头像
export const uploadAvatarAPI = (file: File, userId: number) => {
  const formData = new FormData()
  formData.append('avatar', file)
  formData.append('userId', userId.toString())
  return request.post('/user/uploadAvatar', formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}


